package com.song.boot.springstudy.netty.adhesivedisassembly;

import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import io.netty.channel.SimpleChannelInboundHandler;

import java.nio.charset.StandardCharsets;

class ServerHandler extends SimpleChannelInboundHandler<ByteBuf> {
    private int count = 0;
    
    @Override
    protected void channelRead0(ChannelHandlerContext ctx, ByteBuf msg) throws Exception {
        byte[] bytes = new byte[msg.readableBytes()];
        msg.readBytes(bytes);
        System.out.println("服务端接收到数据: " + new String(bytes, StandardCharsets.UTF_8));
        System.out.println("服务端接收到消息数量: " + (++count));
    }
}